package com.zhaojp.demo.listener;

import com.zhaojp.demo.domain.User;
import com.zhaojp.demo.event.UserRegisterEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class UserRegisterSendMailListener implements ApplicationListener<UserRegisterEvent> {
    /**
     * 实现事件 ‘异步‘ 监听
     *
     * @param userRegisterEvent
     */
    @Override
    @Async
    public void onApplicationEvent(UserRegisterEvent userRegisterEvent) {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        User user = userRegisterEvent.getUser();
        System.out.println("发送邮件通知....完毕>>>" + user.getName());
    }
}
